/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package users.tag;

import java.io.IOException;
import java.util.Collection;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.JspFragment;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import javax.servlet.jsp.tagext.TagSupport;
import tracker.TrackerHelper;
import tracker.Users;

/**
 *
 * @author Hiro
 */
public class ViewSingleUserTagHandler extends TagSupport {

    private String userName;
    private int userLevel, userId;
    private float leechAmount, seedAmount;

    /**
     * Called by the container to invoke this tag. The implementation of this
     * method is provided by the tag library developer, and handles all tag
     * processing, body iteration, etc.
     */
    @Override
    public int doStartTag() throws JspException {
        return super.doStartTag();
    }

    /**
     * This method is called after the JSP engine finished processing the tag.
     *
     * @return EVAL_PAGE if the JSP engine should continue evaluating the JSP
     * page, otherwise return SKIP_PAGE. This method is automatically generated.
     * Do not modify this method. Instead, modify the methods that this method
     * calls.
     */
    @Override
    public int doEndTag() throws JspException {
        JspWriter out = pageContext.getOut();
        try {
            TrackerHelper helper = new TrackerHelper();
            Users user = helper.getUserById(userId);
            out.println("<li>"
                    + "<h2>  " + user.getUserName() + "</h2>" + "<table>");
            out.println("<tr><td>Level: </td>" + "<td><div id='userLevel" + user.getUserLevel()+"'/> "+"<a>" + user.getUserLevel() + "</a></div></td><tr>");
            out.println("<tr><td>Leech Amount: </td>" + "<td>" + user.getLeechAmount() + "GB</td><tr>");
            out.println("<tr><td>Seed Amount: </td>" + "<td>" + user.getSeedAmount() + "GB</td><tr>");
            out.println("<tr><td>Ratio: </td>" + "<td>" + (user.getSeedAmount()/user.getLeechAmount()) + "</td><tr></table></li>");
            out.println("<tr><td></td>" + "<td><button class=\"bg-color-yellow\" type=\"button\" name=\"back\" onclick=\"history.back()\">Back</button></td>");
            //out.println("<br>Pointses: " + user.getPointses());
        } catch (Exception e) {
            throw new JspException(e.toString());
        }
        return EVAL_PAGE;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public void setUserLevel(int userLevel) {
        this.userLevel = userLevel;
    }

    public void setLeechAmount(float leechAmount) {
        this.leechAmount = leechAmount;
    }

    public void setSeedAmount(float seedAmount) {
        this.seedAmount = seedAmount;
    }

    public void setUserId(int userId) {
        this.userId = userId;
    }
}
